<template>
  <dtDialog
    title="日志详情"
    :visible.sync="dialogVisible"
    :footer-slot="true"
  >
    <el-form
      slot="content"
      :model="form"
      label-position="right"
      :label-width="log.logMode==2&&log.annex? '174px':'72px'"
    >
      <el-form-item label="账号">
        <el-input v-model.trim="log.account" disabled />
      </el-form-item>
      <el-form-item label="用户姓名">
        <el-input v-model.trim="log.realName" disabled />
      </el-form-item>
      <el-form-item label="服务名称">
        <el-input v-model.trim="log.appName" disabled />
      </el-form-item>
      <el-form-item label="操作模块">
        <el-input v-model.trim="log.logModule" disabled />
      </el-form-item>
      <el-form-item label="日志名称">
        <el-input v-model.trim="log.logContent" disabled />
      </el-form-item>
      <el-form-item label="请求地址">
        <el-input v-model.trim="log.requestUrl" disabled />
      </el-form-item>
      <el-form-item label="客户端IP">
        <el-input v-model.trim="log.clientIp" disabled />
      </el-form-item>
      <el-form-item label="服务端IP">
        <el-input v-model.trim="log.serverIp" disabled />
      </el-form-item>
      <el-form-item label="浏览器">
        <el-input v-model.trim="log.clientBrowser" disabled />
      </el-form-item>
      <el-form-item label="操作系统">
        <el-input v-model.trim="log.clientOs" disabled />
      </el-form-item>
      <el-form-item label="状态">
        <el-input v-model.trim="log.status" disabled />
      </el-form-item>
      <el-form-item label="失败原因">
        <el-input v-model.trim="log.failReason" :rows="5" type="textarea"
                  disabled class="limit" />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-input v-model.trim="log.createTime" disabled />
      </el-form-item>
      <el-form-item label="请求方式">
        <el-input v-model.trim="log.httpMethod" disabled />
      </el-form-item>
      <el-form-item label="请求参数">
        <el-input v-model.trim="log.requestParams" :rows="5" type="textarea"
                  disabled class="limit" />
      </el-form-item>
      <el-form-item label="返回结果">
        <el-input v-model.trim="log.requestResult" :rows="5" type="textarea"
                  disabled class="limit" />
      </el-form-item>
      <el-form-item v-if="log.logMode==2&&log.annex" label="导入执行结果信息">
        <el-input v-model.trim="log.annex.tip" disabled />
      </el-form-item>
      <el-form-item v-if="log.logMode==2&&log.annex" label="失败的明细文件的下载url">
        <el-link :underline="false" @click="clickUrl"> {{ log.annex.fileName }}</el-link>
        <!-- <el-input id="fileNameId" v-model="log.annex.fileName" @click.native="clickUrl"> -->
        <!-- <el-button type="text" @click="clickUrl">{{ log.annex.fileName }}</el-button> -->
        <!-- </el-input> -->
      </el-form-item>
      <!-- <el-form-item v-if="log.logMode==2&&log.annex" label="失败明细文件名">
        <el-input v-model.trim="log.annex.fileName" :rows="5" type="textarea" disabled />
      </el-form-item> -->
      <el-form-item v-if="log.logMode==2&&log.annex" label="导入成功名单">
        <el-input v-model.trim="log.annex.successList" :rows="5" type="textarea"
                  disabled class="limit" />
      </el-form-item>
      <el-form-item v-if="log.logMode==2&&log.annex" label="导入失败名单">
        <!-- <div style="white-space: pre-line">
          <div style="white-space: pre-line">{{ log.annex.failMap }}</div>
        </div> -->
        <el-input v-model.trim="log.annex.failMap" :rows="5" type="textarea"
                  disabled class="limit" />
      </el-form-item>
      <el-form-item v-if="log.logMode==2&&log.annex" label="备注">
        <el-input v-model.trim="log.annex.remark" :rows="5" type="textarea"
                  disabled class="limit" />
      </el-form-item>
    </el-form>
  </dtDialog>
</template>
<script>
import
configApi
from '@/framework/api/zoningManage'
import { default as request, cloud } from '@/framework/utils/request'
import { detail } from '@/framework/api/developerCenter/operationLog'

export default {
  name: 'OperateLog',
  data() {
    return {
      dialogVisible: false,
      log: {
        annex: {
          successList: ''
        }
      },
      form: {},
      options: {}
    }
  },
  methods: {

    clickUrl() {
      request({
        url: cloud.dqbasic + this.log.annex.errorDownloadPath,
        method: 'get',
        responseType: 'arraybuffer'
      }).then((res) => {
        const blob = new Blob([res.data], {
          type: 'application/vnd.ms-excel'
        })
        const elink = document.createElement('a')
        elink.download = this.log.annex.fileName // 下载文件名称
        elink.href = URL.createObjectURL(blob)
        document.body.appendChild(elink)
        elink.click()
        document.body.removeChild(elink) // 下载完成移除元素
        window.URL.revokeObjectURL(elink) // 释放掉blob对象
      })
    },
    openDialog(row) {
      this.dialogVisible = true
      const params = {
        logId: row.logId
      }
      detail(params).then((resp) => {
        this.log = { ...resp.data }
        if (this.log.logMode == 2) {
          if (this.log.annex) {
            if (this.log.annex.successList && this.log.annex.successList.length > 0) {
              this.log.annex.successList = this.log.annex.successList.join(',')
            }

            let result = ''
            const keys = Object.keys(this.log.annex.failMap); const values = Object.values(this.log.annex.failMap)
            keys.forEach((item, index) => {
              result = result ? `${result}
${item}:${values[index]}` : `${item}:${values[index]}`
            })
            this.log.annex.failMap = result
          }
        }
        this.log.status = this.log.status == 0 ? '成功' : this.log.status == 1 ? '逻辑失败' : '异常失败'
      })
    }
  }
}
</script>
<style lang="scss" scoped>
    .log{
    }
    .el-table .cell {
      white-space: nowrap;
    }
    .dialog-footer{
      text-align: center;
    }
    .table-header{
      background-color: chartreuse;
    }
    ::v-deep .popperClass.el-date-picker {
  width: 220px;
  height: 200px;
  &__header-label {
    font-size:14px;
  }
  .el-picker-panel__content {
    width: 220px;
    height: 200px;
    margin-left: 0;
  }
  .el-year-tabel td {
    padding: 5px 0;
    .cell {
      width: 32px;
      height: 32px;
    }
  }
}
</style>
